package com.central.apps.handler;

import com.central.app.service.HandlerService;
import com.central.apps.handler.base.LvBaseHandler;
import com.central.bizcommon.model.flow.FlowNode;
import com.central.bizcommon.model.flow.FlowOpinion;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2022/8/12.
 */
@Component
@Slf4j
public class ContracttemplateHandler extends LvBaseHandler {
    @Autowired
    private HandlerService handlerService;



    //提交审批前，进行逻辑判断
    public String beforeExcuteFlow(String app, Long id, FlowNode flowNode, FlowOpinion op) throws Exception {


        if("contracttemplateApp".equals(app)){
            String sql = "select * from  tb_file where appname = 'contracttemplateApp' and recordid ="+id;
            List<Map<String, Object>> pmLists = handlerService.findBySql(sql);
            if(CollectionUtils.isEmpty(pmLists)){
                String res ="提交流程审批前，必须先上传合同模板";
                return res;
            }
        }
        return super.beforeExcuteFlow(app,id,flowNode,op);
    }

}
